(function(vc){
    vc.extends({
     data: {
        invoiceDetailSettingModal: {
           edit: false,
           id: '',
           invoiceItemNam: '',
           expenseName: '',
           expenseNum: '',
           expenseRate: '',
           remark: ''
        }
 
     },
     _initMethod: function () {
        
     },
     _initEvent: function () {
         vc.on('invoiceDetailSetting', 'openModal', function(item){
             if(item && item.id){
                 $that.invoiceDetailSettingModal.edit = true;
                 $that.invoiceDetailSettingModal.id = item.id;
                 $that.invoiceDetailSettingModal.invoiceItemName = item.invoiceItemName;
                 $that.invoiceDetailSettingModal.expenseName = item.expenseName;
                 $that.invoiceDetailSettingModal.expenseNum = item.expenseNum;
                 $that.invoiceDetailSettingModal.expenseRate = item.expenseRate;
                 $that.invoiceDetailSettingModal.remark = item.remark;
             }else{
                 $that.invoiceDetailSettingModal.edit = false;
             }
             $('#invoiceDetailSettingModel').modal('show');
         });
         
     },
     methods: {
        saveDetailSetting: function(){
             var _data = {
                 id: $that.invoiceDetailSettingModal.id,
                 invoiceItemName: $that.invoiceDetailSettingModal.invoiceItemName,
                 expenseName: $that.invoiceDetailSettingModal.expenseName,
                 expenseNum: $that.invoiceDetailSettingModal.expenseNum,
                 expenseRate:  $that.invoiceDetailSettingModal.expenseRate,
                 remark: $that.invoiceDetailSettingModal.remark
             };
             if(!_data.invoiceItemName || !_data.expenseName){
                     vc.toast('必填项不能为空');
                     return;
              }
              vc.http.apiPost('/invoice.saveDetailSetting',
                JSON.stringify(_data), 
                {emulateJSON: true}, 
                function(json,res){
                    var _json = JSON.parse(json);
                    if(_json.code==0){
                        $('#invoiceDetailSettingModel').modal('hide');
                        vc.toast(_data.id?'修改明细配置成功':'添加明细配置成功');
                        vc.emit('reloadDetailSetting', 'list', {});
                    }else{
                        vc.toast(_json.msg);
                    }
                },
                function (errInfo,error) {
                    console.log('请求失败处理');
                    vc.toast(errInfo);
                }
              )
         }
     }
 
    });
 
 })(window.vc);